/**
 * Created by qbaozh ON 2021/1/6.
 */
/*
px自动转成rem
注意，修改比例的时候，要改postcss.config.js的rootValue值16和 下面11行的16那个值
*/
(function () {
  /* 计算rem */
  function autoRootFontSize() {
    //(当前屏幕宽度，最小宽度为1200)/1920*16px
    let setSize = Math.max(document.documentElement.getBoundingClientRect().width,1200) / 1920 * 16;
    document.documentElement.style.fontSize = setSize + 'px';
  }
  window.addEventListener('resize', autoRootFontSize);
  autoRootFontSize();

  let orientation = window.matchMedia("(orientation: portrait)");
  let width = document.documentElement.getBoundingClientRect().width; //获取宽度
  function onMatchMeidaChange(orientation:any) {
    if (orientation.matches) {
      // 竖屏
      width = document.documentElement.getBoundingClientRect().width; //获取竖屏宽度
      setTimeout(() => {
        // 重新计算竖屏宽度rem
        autoRootFontSize()
      });
    } else {
      // 横屏
      width = document.documentElement.getBoundingClientRect().width; //获取横屏宽度
      setTimeout(() => {
        // 重新计算横屏宽度rem
        autoRootFontSize()
      });
    }
  }
  onMatchMeidaChange(orientation);
  orientation.addListener(onMatchMeidaChange);
})();


